package com.tz.farmer.controller;


import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.service.KnowledgeService;
import com.tz.farmer.so.BaseSo;
import com.tz.farmer.so.FarmerKnowledgeSo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: 食安知识（h5）
 * @name BusinessController
 * @author: xhj
 * @date: 2021/7/13
 * @version V1.0
 */
@RestController
@RequestMapping("knowledge")
@Api(value = "食安知识（h5）", tags = "食安知识（h5）控制器")
public class KnowledgeController {
    private static Logger logger = LoggerFactory.getLogger(KnowledgeController.class);

    @Resource
    KnowledgeService knowledgeService;

    /**
     * @description:  查询食安知识列表
     * @name businessInfo
     * @author: xhj
     * @date: 2021/7/13 11:35
     * @version V1.0
     */
    @ApiOperation("查询食安知识")
    @GetMapping("knowledgeInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "flag", value = "农/渔（0：农  1：渔）", defaultValue = ""),
    })
    public ResultEx getKnowledgeInfo(BaseSo baseSo) {
        try {
            return knowledgeService.getKnowledgeInfo(baseSo);
        }catch (Exception e){
            logger.error("食安知识获取失败",e);
            return ResultEx.builder().makeFailedResult("食安知识获取失败");

        }
    }

    /**
     * @description:  查询食安知识详情
     * @name businessInfo
     * @author: xhj
     * @date: 2021/7/13 11:35
     * @version V1.0
     */
    @ApiOperation("查询食安知识详情")
    @GetMapping("knowledgeDetailInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "食安知识id", defaultValue = ""),
    })
    public ResultEx getKnowledgeDetailInfo(FarmerKnowledgeSo farmerKnowledgeSo) {
        try {
            return knowledgeService.getKnowledgeDetailInfo(farmerKnowledgeSo);
        }catch (Exception e){
            logger.error("食安知识详情获取失败",e);
            return ResultEx.builder().makeFailedResult("食安知识详情获取失败");

        }
    }

}
